<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html{
            font-size:12px;
        }
    </style>
</head>
<body>
    当前时间：<span id="insertPoint"></span><br>
    <button id="btn_test">开始</button>
</body>
</html>
<script>
    getCurrentTime();
    var index=0;    //定义一个全局的变量，用以存放定时器返回的数值
    function getCurrentTime(){
        let date = new Date();
        document.getElementById("insertPoint").innerHTML = date.toLocaleString(); 
    }
    document.getElementById("btn_test").addEventListener('click',()=>{
        let node = document.getElementById("btn_test");
        if(node.innerHTML == '停止'){
            clearInterval(index);    //停止，根据index确定某个具体的定时器
            document.getElementById("btn_test").innerHTML = '开始';
        }else{
            index  = setInterval(getCurrentTime,1000);
            document.getElementById("btn_test").innerHTML = '停止';
        }
    },false);
</script>